package com.diyizu.controller.impl;

import com.diyizu.controller.ILoginController;
import com.diyizu.controller.IRegController;
import com.diyizu.controller.StatisticalReportController;
import com.diyizu.factory.Factory;
import com.diyizu.service.IRegService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Scanner;

public class Extensions {
    Scanner sc = new Scanner(System.in);
    private static final Logger LOGGER = LoggerFactory.getLogger(Extensions.class);

    //扩展功能入口
    public void start() {
        ILoginController iLoginController = Factory.getILoginController();
        String userName = iLoginController.getUserName();
        while (true) {
            //键盘录入
            System.out.println("请输入您的选择: 1.导出学生信息  2.导入学生信息  3.统计学生信息  4.查看注册时间  5.修改密码  6.修改邮箱  7.返回上级菜单");
            String choice = sc.next();
            //switch
            switch (choice) {
                case "1":
                    long start = System.currentTimeMillis();
                    ToExcle toExcle = Factory.getToExcle();
                    toExcle.toExcel();
                    LOGGER.info(userName+"导出数据");
                    long end = System.currentTimeMillis();
                    System.out.println("导出成功,此次导出数据耗时:"+(end-start)+"毫秒");

                    break;
                case "2":
                    BayExcle bayExcle = Factory.getBayExcle();
                    bayExcle.bayExcle();
                    System.out.println("导入成功");
                    break;
                case "3":
                    StatisticalReportController statisticalReportController = Factory.getStatisticalReportController();
                    statisticalReportController.stuTongJi();
                    break;
                case "4":
                    IRegService iRegService = Factory.getIRegService();
                    String userRegTime = iRegService.getUserRegTime(userName);
                    System.out.println("您的注册时间是"+userRegTime);
                    break;
                case "5":
                    IRegController iRegController =Factory.getIRegController();
                    iRegController.updatePass();
                    LOGGER.info(userName+"用户修改了密码");
                    System.out.println("恭喜你修改成功");
                    break;
                case "6":
                    IRegController regController =Factory.getIRegController();
                    regController.updateEmail();
                    LOGGER.info(userName+"修改了邮箱");
                    System.out.println("恭喜你修改成功");
                    break;
                case "7":
                    return;
                default:
                    System.out.println("您的输入有误,请重新输入");
            }
        }
    }
}
